﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TheVerge.Base.Models
{
    public class VMHubs : VMSection<VMHub>
    {
        public override string DisplayName { get { return @"Hubs"; } }

        protected override void Load(Action<VMHub[]> results)
        {
            API.GetHubs(hubs =>
            {
                if (hubs == null)
                    results(null);
                else
                    results(hubs.All.OrderBy(h => h.Title).Select(h => new VMHub(h)).ToArray());
            }, error => results(null));
        }
    }

    public class VMHub : VMEntries<ArticleEntry>
    {
        public override string DisplayName { get { return @"Hub"; } }

        public int HubId { get; private set; }
        public string Title { get; private set; }

        public VMHub(Hub h) : this(h.Id, h.Title) { }
        public VMHub(int hubId, string title)
        {
            HubId = hubId;
            Title = title;
        }

        protected override void LoadMoreImp(Action<APIResponse<ArticleEntry>> OnFinished, Action<Exception> OnError)
        {
            API.GetHubEntries(LastPageLoaded + 1, HubId, OnFinished, OnError);
        }

        public override string ToString()
        {
            return Title;
        }
    }
}
